<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
    <style type="text/css">
        .header {
            padding: 2.5rem 0.5rem 2rem 0.5rem;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="padding-top:25px;">
        <a class="aui-pull-left aui-btn" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">可大金服OA</div>
        <a class="aui-pull-right aui-btn nav-btn">
        </a>
    </header>

    <!-- <div class="user-list">
    <dl>
        <dt>文章标题文章标题文章标题</dt>
        <dd>申请时间：2018-11-25</dd>
    </dl>
</div> -->
    <div id="list"></div>

    <!-- <div class="foot-t"></div>
<ul class="foot">
  <li>
    <i class="aui-iconfont aui-icon-home"></i>
    <p>首页</p>
  </li>
  <li>
    <i class="aui-iconfont aui-icon-my"></i>
    <p>我的</p>
  </li>
</ul> -->
</body>

<script type="text/template" id="template">
    <div class="user-list">
        {{~it:value:index}}
        <dl onclick="record({{=value.id}})">
            <dt>{{=value.name}}</dt>
            <dd>申请时间：
                <dd1>{{=value.create_time}}</dd1>
            </dd>
        </dl>
        {{~}}
    </div>
</script>

<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript">
    function openClub() {
        var delay = 0;
        if (api.systemType != 'ios') {
            delay = 300;
        }
        api.openWin({
            name: 'club_win',
            url: './html/club_win.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    }
    $(".nav-btn").on("click", function() {
        $(".nav").slideToggle(100);
    })
    $(".nav .aui-list-item").on("click", function() {
        $(".nav").hide();
    })

    function closeWin() {
        api.closeWin({});
    }

    var page = 0;
    var p = 0;
    apiready = function() {
        updateData();
        addObserver();
        down_refresh();
    }

    function updateData(n) {
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        var userid = $api.getStorage('id');
        if (n) {
            page += 1;
        } else {
            page = 1;
        }

        api.ajax({
            url: 'http://oa.big-wealth.com/index.php?m=&c=info&a=info_apply_list&api_auth_id=' + userid,
            method: 'post',
            data: {
                values: {
                    p: page,
                }
            }

        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                // console.log(JSON.stringify(ret));

                for (var i = 0; i < ret.data.length; i++) {
                    var index = getDate(ret.data[i].create_time).search(' ')
                    ret.data[i].create_time = getDate(ret.data[i].create_time).substr(0, index);
                }
                // alert(ret.yema);
                p = ret.yema;
                templateFun(ret.data);
                api.refreshHeaderLoadDone();
                api.hideProgress();
            } else {
                alert(JSON.stringify(err));
            }
        });

    }

    function templateFun(data) {
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        // $api.html(list, html);

        if (page == 1) {
            $api.html(list, html);
        } else {

            if (!data) {
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            $api.append(list, html);
        }

    }

    // 下拉刷新
    function down_refresh() {

        api.setRefreshHeaderInfo({
            visible: true,
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            page = 1;

            updateData();
        });
    }

    // 上拉加载
    function addObserver() {

        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err) {
            // alert(page);

            if (p <= page) {
                api.toast({
                    msg: '没有更多了',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            updateData(true);
        });
    }

    function record(id) {
        // var userid = $api.getStorage('id');
        // api.ajax({
        //     url: 'http://oa.big-wealth.com/index.php?m=&c=info&a=info_applyst&api_auth_id=' + userid + '&id=' + id,
        //     method: 'get',
        //
        // }, function(ret, err) {
        //     if (ret) {
        //         // alert( JSON.stringify( ret ) );
        //         if (ret.st == 1) {
        //             api.openWin({
        //                 name: 'content',
        //                 url: './content.html',
        //                 pageParam: {
        //                     apply: 1,
        //                     id: id,
        //                 }
        //             });
        //
        //         } else {
        //             alert('申请尚未通过！');
        //         }
        //     } else {
        //         // alert( JSON.stringify( err ) );
        //     }
        // });

        api.openWin({
            name: 'content',
            url: './content.html',
            pageParam: {
                id: id,
            }
        });

    }
</script>

</html>
